<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
use Org\Util\Tree;
// +----------------------------------------------------------------------
// | Date:2016年12月19日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class CategoryController extends CommonController{
    
    
    public function _initialize(){
        parent::_initialize();
        $this->model = D('Category');    
    }
    
    
    public function index(){
        
		$result = $this->model->order(array("listorder"=>"asc"))->select();
		$tree = new Tree();
		$tree->icon = array('&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ ');
		$tree->nbsp = '&nbsp;&nbsp;&nbsp;';
		foreach ($result as $r) {
		    $r['style'] = $r['pid'] == 0 ? "style='color:red;'" : '';
			$r['str_manage'] = '<a href="' . U("add", array("cid" => $r['cid'])) . '">添加子分类</a> | <a href="' . U("edit", array("id" => $r['cid'])) . '">编辑</a>';
			$r['id']=$r['cid'];
			$r['parentid']=$r['pid'];
			$array[] = $r;
		}
		
		$tree->init($array);
		$str = "<tr>
		            <th width='15'><label><input type='checkbox' class='js-check' data-yid='js-check-y' data-xid='js-check-x'  name='ids[]' value='\$id' ></label></th>
					<td><input name='listorders[\$id]' type='text' size='3' value='\$listorder' class='input input-order' ></td>
					<td>\$id</td>
					<td style='text-align:left;'>\$spacer <a href='\$url' target='_blank' \$style>\$name</a></td>
					<td>\$str_manage</td>
				</tr>";
		$list = $tree->get_tree(0, $str);
        $this->assign('list',$list);
        $this->display();
    }
    
    //curd后置操作，写入缓存
    public function curd_after(){
        $data = $this->model->order("listorder")->select();
        F('category',$data);
    }
    
    
    
}